<template>
  <div class="base-container">
    <t-form ref="form" :data="queryParams" label-width="80" @submit="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}" @reset="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="成果名称" name="name">
            <t-input
              v-model="queryParams.name"
              clearable
              placeholder="请输入成果名称"
              style="width: 240px"
            />
          </t-form-item>
          <t-form-item label="应用领域" name="applicationField">
            <t-select style="width: 240px" clearable v-model="queryParams.applicationField"
                      :options="dict.type.application_field">
            </t-select>
          </t-form-item>
          <t-form-item label="创新类别" name="innovationCategory">
            <t-select style="width: 240px" clearable v-model="queryParams.innovationCategory"
                      :options="dict.type.innovation_category">
            </t-select>
          </t-form-item>
          <t-form-item label="成果状态" name="innovationStatus">
            <t-select  style="width: 240px" clearable v-model="queryParams.innovationStatus"
                       :options="dict.type.innovation_status">
            </t-select>
          </t-form-item>
          <!--          <t-form-item label="审批状态" name="approveStatus">-->
          <!--            <t-select style="width: 240px" clearable v-model="queryParams.approveStatus"-->
          <!--                      :options="dict.type.approve_status">-->
          <!--            </t-select>-->
          <!--          </t-form-item>-->
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <div class="btn-group-inline">
      <t-button @click="handleExport" variant="outline" theme="primary">
        <t-icon name="download" slot="icon"/>
        导出
      </t-button>
    </div>
    <t-table
      rowKey="id"
      :data="data"
      :columns="columns"
      hover
      :pagination="pagination"
      :loading="dataLoading"
    >
      <template #applicationField="{row}">
        {{ row.applicationField | filterByDict(dict.type.application_field) }}
      </template>
      <template #innovationCategory="{row}">
        {{ row.innovationCategory | filterByDict(dict.type.innovation_category) }}
      </template>
      <template #innovationStatus="{ row }">
        <t-tag  @click="dialog.header='审批记录';dialog.objId=row.id;dialog.open_approve_list=true" class="cursor-pointer" :theme="handleTheme(row.innovationStatus, dict.type.innovation_status)" variant="light">
          {{ row.innovationStatus | filterByDict(dict.type.innovation_status) }}
        </t-tag>
      </template>
      <!--      <template #approveStatus="{ row }">-->
      <!--        <t-tag v-if="row.approveStatus === '2'" theme="primary" variant="light">审核中</t-tag>-->
      <!--        <t-tag v-else-if="row.approveStatus === '1'" theme="warning" variant="light">暂存</t-tag>-->
      <!--        <t-tag v-else-if="row.approveStatus === '3'" theme="success" variant="light">通过</t-tag>-->
      <!--        <t-tag v-else-if="row.approveStatus === '4'" theme="danger" variant="light">退回</t-tag>-->
      <!--        <t-tag v-else theme="warning" variant="light">未提交</t-tag>-->
      <!--      </template>-->
      <template #op="{ row }">
        <t-button @click="dialog.header=row.name;dialog.objId=row.id;dialog.open_innovation_detail=true" size="small" variant="text" class="t-button-link">
          <t-icon name="info-circle" slot="icon"/>
          详情
        </t-button>
      </template>
    </t-table>
    <innovation-detail-dialog :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_innovation_detail" v-if="dialog.open_innovation_detail"></innovation-detail-dialog>
    <approve-list :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_approve_list" v-if="dialog.open_approve_list"></approve-list>
  </div>
</template>

<script>
import InnovationDetailDialog from "../../wcx/innovation/components/innovation-detail-dialog.vue";
import ApproveList from "../../wcx/approve/components/approve-list.vue";

export default {
  name: "wcx-index",
  dicts: ["application_field", "innovation_category", "approve_status", "innovation_status"],
  components:{
    InnovationDetailDialog,
    ApproveList
  },
  data() {
    return {
      dialog:{
        header:"",
        objId:0,
        open_innovation_detail: false,
        open_approve_list: false,
      },
      data: [],
      columns: [
        {
          colKey: "name",
          title: "成果名称",
          align: "center",
          width: 220,
        },
        {
          colKey: "applicationProject",
          title: "应用项目",
          align: "center",
        },
        {
          colKey: "applicationField",
          title: "应用领域",
          align: "center",
        },
        {
          colKey: "innovationCategory",
          title: "创新类别",
          align: "center",
        },
        {
          colKey: "leaderName",
          title: "负责人",
          align: "center",
        },
        {
          colKey: "deptName",
          title: "工作单位",
          align: "center",
        },
        {
          colKey: "innovationStatus",
          title: "成果状态",
          align: "center",
          width:120
        },
        // {
        //   colKey: "approveStatus",
        //   title: "审批状态",
        //   align: "center",
        //   width:120
        // },

        {
          colKey: "createTime",
          title: "申报时间",
          align: "center",
          width: 200
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 120
        },
      ],
      dataLoading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        applicationField: '',
        innovationCategory: '',
        name: '',
        innovationStatus: '',
      },
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10,20,30],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination,pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    }
  },
  created() {
    Object.assign(this.queryParams,this.handelQuery(this.queryParams,this.$route.query))
    this.getList();
  },
  methods: {
    getList() {
      this.dataLoading = true;
      this.$api.wcx.apply.innovationIndex(this.queryParams).then(
        (res) => {
          this.data = res.rows;
          this.pagination.total = res.total;
          this.dataLoading = false;
        }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },
    handleExport() {
      this.$download(`/wcx/excel/exportAllList`,this.queryParams, `微创新成果列表_${new Date().getTime()}.xls`)
    }
  }
}
</script>

<style lang="less" scoped>
//.t-col{
//  border: 1px solid #000000;
//  height: 100%;
//  margin-right: -1px;
//  margin-bottom: -1px;
//}
</style>
